<?php
namespace app\api\service;

use think\Exception;

class SaleService{
    public function __construct(){

        $this->url = 'http://hddc01.superbrandmall.com:9000';
        $this->path='/pod-open/s/v1/trade_settlement/uploadForBatch';
        $this->bloc = '0000';
        $this->accessKey = '654321';
        $this->accessSecret = '123456';
    }


    /**
     * 生成签名
     */
    public function getSign(){
        $timestamp = time()*1000;
        $sign = bin2hex(md5($this->path.$this->bloc.$this->accessKey.$timestamp.$this->accessSecret));
        $url = $this->url.$this->path.'?'.'bloc='.$this->bloc.'&accessKey='.$this->accessKey.'&timestamp='.$timestamp.'&sign='.$sign;
        return $url;
    }

    /**
     * 请求
     */
    public function requestPost($data){
        $url = $this->getSign();
        try {
            $result =json_decode( httpRequest($url,'POST',json_encode($data)),true);
            return $result;
        }catch (Exception $e){
            throw new Exception($e->getMessage());
        }

    }

}